<?php
/**
* Main point for serving all types of images
*/

$image_id = $variable->get('id', 'integer', 0);
$code = $variable->get('code', 'string', '');
$size = $variable->get('size', 'string', ''); # serve requested size whaterver other options may be
$is_thumbnail = $variable->get('thumbnail', 'string', 'false')=='true';

# Check for the validtiy of the image
# This protects serving images to saved/bookmarked images
# If failed, increases the invalid access counter

$image = new images();
if($image->is_valid($image_id, $code))
{
	# Force client side caching
	headers::cache();
	
	$scanner = new scanner();
	if($is_thumbnail)
	{
		# Show thumbnail
		$scanner->preview_thumbnail($image_id, $code);
	}
	else if($size)
	{
		# Show requested image
		# Uses cached images
		$scanner->preview_size($image_id, $code, $size);
	}
	else
	{
		# Show large / original image
		$scanner->preview($image_id, $code);
	}
}
else
{
	stopper::message('Invalid image request.', false);
}
?>